<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<%@ taglib prefix="his_fns" uri="/WEB-INF/tlds/his_fns.tld" %>
<script type="text/javascript">
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
</script>
<div class="app">
    <section class="layout">
        <section class="main-content col-lg-12" id="expExportDiv">
            <div class="content-wrap">
                <div class="wrapper" style="bottom: 50px;">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#" onclick="loadDiv('mainCenterDiv','${ctx}/csm/buyExpPlan/createPlanIndex')">采购计划生成</a>
                        </li>
                    </ul>
                    <section class="panel panel-default">
                        <div class="panel-body">
                            <div class="table-responsive no-border">
                                <div class="datatable-top">
                                    <div class="pull-left">
                                        <form:form id="searchForm" modelAttribute="expBuyPlan" onsubmit="return loadDivForm('mainCenterDiv','searchForm',
                                        '${ctx}/csm/buyExpPlan/createPlanIndex');" method="post" class="form-inline">
                                            <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
                                            <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
                                            <div class="form-group">
                                                <label class=" control-label">发放单位：</label>
                                                <form:select  path="expProvideApplication.storageOut" maxlength="64" class="form-control" data-parsley-required="true">
                                                    <from:option value="" label=""/>
                                                    <form:options items="${his_fns:getAuditSupplyList()}"  htmlEscape="false" itemLabel="storageName" itemValue="storageCode"/>
                                                </form:select>
                                            </div>&nbsp;&nbsp;
                                            <div class="form-group">
                                                <label class=" control-label">开始日期：</label>
                                                <input name="startDate" id ="startDate1"  htmlEscape="false" class="form-control Wdate" value="<fmt:formatDate value="${expBuyPlan.startDate}"
                                                pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>" onfocus="WdatePicker({isShowClear:false,readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" data-parsley-required="true"/>
                                            </div>
                                            <div class="form-group">
                                                <label class=" control-label">结束日期：</label>
                                                <input name="stopDate" id ="stopDate1"  htmlEscape="false" class="form-control Wdate" value="<fmt:formatDate value="${expBuyPlan.stopDate}"
                                                pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>" onfocus="WdatePicker({isShowClear:false,readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" data-parsley-required="true"/>
                                            </div>
                                            <div class="form-group">
                                                <input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
                                                <input class="btn btn-primary" type="button" onclick="saveListForm()" value="保存" />
                                                <input id="btnPrintByStorageIn" class="btn btn-primary" type="submit" value="按科室汇总打印单据" />
                                                <input id="btnPrintByExpName" class="btn btn-primary" type="submit" value="按名称汇总打印单据" />
                                            </div>
                                        </form:form>
                                    </div>
                                </div>
                                <form id="saveListForm" action="${ctx}/csm/buyExpPlan/saveExpBuyPlanCreate" method="post" class="form-inline">
                                    <input type="hidden" name="startDate" id="startDate"/>
                                    <input type="hidden" name="stopDate" id="stopDate"/>
                                    <table id="contentTable" class="table table-bordered table-striped mg-t datatable">
                                        <thead>
                                            <tr>
                                                <th hidden>jsonText</th>
                                                <th hidden>infoId</th>
                                                <th>编码</th>
                                                <th>名称</th>
                                                <th hidden>产品类别</th>
                                                <th hidden>包装数量</th>
                                                <th>规格</th>
                                                <th>单位</th>
                                                <th>生产厂家</th>
                                                <th>采购数量</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        <c:forEach items="${page.list}" var="expBuyPlan" varStatus="idx">
                                            <tr xia="${idx.index}">
                                                <td hidden> ${expBuyPlan.infoId}<input type="hidden" name="expBuyPlanList[${idx.index}].infoId" class="form-control"
                                                        value="${expBuyPlan.infoId}"></td>
                                                <td> ${expBuyPlan.expCode}<input type="hidden" name="expBuyPlanList[${idx.index}].expCode" class="form-control"
                                                        value="${expBuyPlan.expCode}"></td>
                                                <td> ${expBuyPlan.expName}<input type="hidden" name="expBuyPlanList[${idx.index}].expName" class="form-control"
                                                        value="${expBuyPlan.expName}"></td>
                                                <td hidden>${fns:getDictLabel(expBuyPlan.expNameDict.expStyle,'EXP_STYLE','')} ${expBuyPlan.expStyle}<input type="hidden"
                                                          name="expBuyPlanList[${idx.index}].expStyle" class="form-control" value="${expBuyPlan.expStyle}"></td>
                                                <td hidden> ${expBuyPlan.expProvideApplication.packageNum}</td>
                                                <td> ${expBuyPlan.packageSpec}<input type="hidden" name="expBuyPlanList[${idx.index}].packageSpec" class="form-control"
                                                        value="${expBuyPlan.packageSpec}"></td>
                                                <td> ${fns:getDictLabel(expBuyPlan.packageUnit,'SPEC_UNIT','')}<input type="hidden" name="expBuyPlanList[${idx.index}].packageUnit" class="form-control"
                                                        value="${expBuyPlan.packageUnit}"></td>
                                                <td> ${his_fns:getExpSupplierById(expBuyPlan.vedorName)}<input type="hidden" name="expBuyPlanList[${idx.index}].vedorName" class="form-control"
                                                        value="${expBuyPlan.vedorName}"></td>
                                                <td> ${expBuyPlan.buyQuantity}<input type="hidden" name="expBuyPlanList[${idx.index}].buyQuantity" class="form-control"
                                                        value="${expBuyPlan.buyQuantity}"></td>
                                            </tr>
                                        </c:forEach>
                                    </table>
                                </form>
                                <div class="pagination">${page}</div>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </section>
    </section>
</div>
<script type="text/javascript">
    //保存
    function saveListForm() {
        $('#startDate').val($('#startDate1').val());
        $('#stopDate').val($('#stopDate1').val());
        $("#saveListForm").ajaxSubmit({
            success: function (data) {
                if (data.code == 'success') {
                    toastr.success(data.data);
                    $('#startDate').val('');
                    $('#stopDate').val('');
                    $("#contentTable tr:not(:first)").html("");
                } else {
                    toastr.error(data.data);
                }
            },
            error: function (data) {
                toastr.error(data.data);
            }
        });
    }
    $(function(){
        $("#btnPrintByStorageIn").click(function(){
            var remarks='0';
            var startDate=$("#startDate1").val();
            var stopDate=$("#stopDate1").val();
            printPdf('${ctx}/csm/expProvideApplication/expProvidePrint?remarks='+remarks+'&startDate='+startDate+'&stopDate='+stopDate);
        })
    })
    $(function(){
        $("#btnPrintByExpName").click(function(){
            var startDate=$("#startDate1").val();
            var stopDate=$("#stopDate1").val();
            var remarks='1';
            printPdf('${ctx}/csm/expProvideApplication/expProvidePrint?remarks='+remarks+'&startDate='+startDate+'&stopDate='+stopDate);
        })
    })
</script>